Skip to content

fix: support Java records as JPA @IdClass - #2819

Closed
hantsy wants to merge 1 commit into
eclipse-ee4j:masterfrom
hantsy:fix/record-idclass
Closed

fix: support Java records as JPA @IdClass#2819
hantsy wants to merge 1 commit into
eclipse-ee4j:masterfrom
hantsy:fix/record-idclass

Conversation

@hantsy

@hantsy hantsy commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

@
Support a java.lang.Record used as a JPA @IdClass.

Root cause

CMPPolicy.createPrimaryKeyInstance() assumed the id class could be built via a no-arg constructor followed by accessor.setValue(...). Records have neither a no-arg constructor nor writable fields.

Fix

Detect a record pkClass and build the primary key instance via RecordInstantiationPolicy using the record canonical constructor.

Test

TestRecordIdClass uses a RecordIdClass(UUID id, String code) record as the @IdClass of RecordIdClassEntity, covering persist/find and PersistenceUnitUtil.getIdentifier.

Depends on #2817 (record @Embeddable policy plumbing).
@

@
fix: support Java records as JPA @IdClass

createPrimaryKeyInstance() assumed the primary key class could be
built via a no-arg constructor followed by field reflection. Records
have neither a no-arg constructor nor writable fields. Detect a record
pkClass and build it via RecordInstantiationPolicy and its canonical
constructor.
@
@hantsy

hantsy commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Merged into #2817 — the record @IdClass fix is now part of the combined record-support PR. Closing in favor of #2817.

@hantsy hantsy closed this Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant